import styles from './index.less';
import { Modal } from 'antd-mobile';
const { alert } = Modal;
import {Component} from 'react'
export default class Download extends Component{
  state = {
    modal1: false,
    modal2: false
  };
  showModal = key => e => {
    e.preventDefault(); // 修复 Android 上点击穿透
    this.setState({
      [key]: true
    });
  };
  onClose = key => () => {
    this.setState({
      [key]: false
    });
  };

  onWrapTouchStart = e => {
    // fix touch to scroll background page on iOS
    if (!/iPhone|iPod|iPad/i.test(navigator.userAgent)) {
      return;
    }
    const pNode = closest(e.target, '.am-modal-content');
    if (!pNode) {
      e.preventDefault();
    }
  };
  isWeixin = function() {
    //判断是否是微信
    var ua = navigator.userAgent.toLowerCase();
    console.log('​isWeixin -> ua', ua);
    return ua.match(/MicroMessenger/i) == 'micromessenger';
  };
  download = type => {
    if (this.isWeixin()) {
      this.setState({
        modal1: true
      });
    } else {
      if (type === 'andriod') {
        window.location.href =
          'http://app.huangyanyang.cn/__W2A__www.niushengniu.cn_0111143715_legu_signed_zipalign.apk';
      } else {
        alert('ios版本还未上线，敬请期待~');
      }
    }
  };
  render() {
    return (
      <div className={styles.niuyemi_box}>
        <div className={styles.back_niuyemi}>
          <div className={styles.ip_niuyemi} onClick={this.download.bind(this, 'ios')}>
            <img className={styles.ip_img} src={require('src/assets/niuiP.png')} alt="" />
          </div>
          <div className={styles.an_niuyemi} onClick={this.download.bind(this, 'andriod')}>
            <img className={styles.an_img} src={require('src/assets/ninAnd.png')} alt="" />
          </div>
        </div>
        <Modal
          visible={this.state.modal1}
          transparent
          maskClosable={false}
          onClose={this.onClose('modal1')}
          footer={[
            {
              text: 'Ok',
              onPress: () => {
                console.log('ok');
                this.onClose('modal1')();
              }
            }
          ]}
          wrapProps={{ onTouchStart: this.onWrapTouchStart }}
          // afterClose={() => { alert('afterClose'); }}
        >
          检测到您在微信打开下载页，请点击右上角的【...】，选择在【浏览器打开】，然后继续下载操作
        </Modal>
      </div>
    );
  }
}
